package com.hanser.hancoder.core.parser;

import com.hanser.hancoder.exception.BusinessException;
import com.hanser.hancoder.exception.ErrorCode;
import com.hanser.hancoder.model.enums.CodeGenTypeEnum;

public class CodeParserExecutor {

    public static final HtmlCodeParser HTML_CODE_PARSER = new HtmlCodeParser();
    public static final MultiFileCodeParser MULTI_FILE_CODE_PARSER = new MultiFileCodeParser();
    private static Long appId;

    /**
     * 执行代码解析
     *
     * @param codeContent     代码内容
     * @param codeGenTypeEnum 代码生成类型枚举
     * @param appId 应用ID
     * @return 解析结果
     */
    public static Object executeParser(String codeContent, CodeGenTypeEnum codeGenTypeEnum, Long appId) {
        CodeParserExecutor.appId = appId;
        return switch (codeGenTypeEnum) {
            case HTML -> HTML_CODE_PARSER.parserCode(codeContent);
            case MULTI_FILE -> MULTI_FILE_CODE_PARSER.parserCode(codeContent);
            default -> throw new BusinessException(ErrorCode.SYSTEM_ERROR, "不支持的代码生成类型");
        };
    }
}
